#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QMenu>
#include <QAction>
#include <QNetworkAccessManager>//在.pro中加入network
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QbyteArray>

#include "WeatherTool.h"


#include <QLabel>
#include <QList>
#include <QPoint>
#include <QRect>
#include <QTimer>
#include <QMouseEvent>


struct Today
{
    QString date;
    QString wendu;
    QString city;
    QString shidu;
    QString pm25;
    QString quality;
    QString ganmao;
    QString fx;
    QString fl;
    QString type;
    QString sunrise;
    QString sunset;
    QString notice;
};

struct Forecast
{
    QString date;
    QString high;
    QString low;
    QString aqi;
    QString type;
};


QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();

protected:
    bool eventFilter(QObject *watched, QEvent *event);
    void contextMenuEvent(QContextMenuEvent *event);//鼠标事件
    void mouseMoveEvent(QMouseEvent *event);
    void mousePressEvent(QMouseEvent *event);//拖动窗口事件


private slots:
    void slot_exitApp();
    void replayFinished(QNetworkReply *reply);
    void on_searchBt_clicked();
    void on_refreshBt_clicked();

private:
    Ui::Widget *ui;
    QMenu *exitMenu;//右键退出的菜单
    QAction *exitAct;//退出的行为
    QPoint mPos;//窗口移动需要用的点，比如左右上下

    //本地数据
    Today today;
    Forecast forecast[6];

    static const QPoint sun[2];
    static const QRect sunRizeSet[2];
    static const QRect rect[2];

    QTimer *sunTimer;


    QList<QLabel *> forecast_week_list;
    QList<QLabel *> forecast_date_list;
    QList<QLabel *> forecast_aqi_list;
    QList<QLabel *> forecast_type_list;
    QList<QLabel *> forecast_typeIco_list;
    QList<QLabel *> forecast_high_list;
    QList<QLabel *> forecast_low_list;


    //网络请求
    QNetworkAccessManager *manager;
    QString url;//接口连接
    QString city;//访问的城市
    QString cityTmp;//临时存放城市变量，防止输入错误城市的时候，原来的城市名称还在
    WeatherTool tool;//天气工具对象

    void getWeatherInfo(QNetworkAccessManager *manager);
    void parseJson(QByteArray& bytes);
    void setLabelContent();
    void paintSunRiseSet();
    void paintCurve();
    void callKeyBoard();
};
#endif // WIDGET_H
